package fr.pud.client.view.mapstation;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;

import javax.swing.JButton;

import fr.pud.client.images.ImagesDatabase;

/**
 * This class allows the user to create a pointer on the map
 * @author Simon Devineau, Adrien Hierry, Leopold Houdin, Pierre Reliquet
 */
public class ButtonPointer extends JButton {
    private static final long serialVersionUID = 45538958911468082L;
    /**
     * value of the pointer
     */
    private String            name;
    /**
     * image of the pointer
     */
    private Image             img;

    /**
     * A constructor which creates a ButtonPointer with a string
     * @param s
     */
    public ButtonPointer(String s, int colorMmarker) {
        super(s);
        this.name = s;
        switch (colorMmarker) {
            case MapStation.BLUE_POINTER:
                this.img = ImagesDatabase.POINTER_BLUE;
                break;
            case MapStation.ORANGE_POINTER:
                this.img = ImagesDatabase.POINTER_ORANGE;
                break;
            case MapStation.GREEN_POINTER:
                this.img = ImagesDatabase.POINTER_GREEN;
                break;
            case MapStation.PURPLE_POINTER:
                this.img = ImagesDatabase.POINTER_PURPLE;
                break;
            default:
                this.img = ImagesDatabase.POINTER_RED;
                break;
        }
    }

    /**
     * Paint the pointer on the graphic
     */
    @Override
    protected void paintComponent(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setColor(Color.RED);
        // g2d.setBackground(Color.BLUE);
        g2d.drawImage(this.img, 0, 0, 20, 30, null);
        // g2d.fillOval(0, 0, 18, 18);
        //
        // int[] xPoints ={5,10,15};
        // int [] yPoints = {18,30,18};
        // g2d.fillPolygon(xPoints, yPoints,3);
        // g2d.setColor(Color.BLACK);
        // g2d.drawArc(0, 0, 18, 18, 60, 300);
        // g2d.drawPolygon(xPoints, yPoints,3);;
        g2d.setColor(Color.WHITE);
        if (this.name.length() == 1) {
            g2d.drawString(this.name, 6, 15);
        }
        else {
            g2d.drawString(this.name, 3, 15);
        }
    }
}
